package com.project.controller;

import com.project.bean.UserBean;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDate;

/**
 * 应用控制器
 */
@Controller//标识spring主键
public class TestController {
    //客户端以斜杠mytest请求，由当前方法进行处理
    @RequestMapping("/mytest")
    public String test(){
        //设置转发路径
        return "redirect:/html/index.html";
    }

    @RequestMapping("add")//按照表单名和属性名相同的原则，将表单数据封装为实体对象
    public void add(UserBean user,//表单名和不形参名一样时，需要别名，用@RequestParm("别名")，
                    String code,//说明哪个表单值填充当前表单对象
                    int money,
                    LocalDate birthday,
                    HttpServletResponse response)throws Exception{
        response.setContentType("text/html;charset=utf-8");
        response.getWriter().println(user+"   code="+code+"   money"+money+"    birthday="+birthday);
    }
}
